package org.rslai.autotest.core.page.impl;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;

import org.rslai.autotest.core.page.Assertions;

/**
 * 一组自定义测试断言方法实现<br>
 * 将junit断言进行了一次封装
 * @author rslai
 */
public class AssertionsImpl implements Assertions {

	public void assertTrue(boolean condition) {
		this.assertTrue(null, condition);
	}

	public void assertTrue(String message, boolean condition) {
		org.junit.Assert.assertTrue(message, condition);
	}

	public void assertFalse(boolean condition) {
		org.junit.Assert.assertFalse(null, condition);
	}

	public void assertFalse(String message, boolean condition) {
		org.junit.Assert.assertFalse(message, condition);
	}
	
	public void assertEquals(String expected, String actual) {
		this.assertEquals(null, expected, actual, true);
	}

	public void assertEquals(String message, String expected, String actual) {
		this.assertEquals(message, expected, actual, true);
	}

	public void assertEquals(String expected, String actual, boolean removeBlank) {
		this.assertEquals(null, expected, actual, removeBlank);
	}

	public void assertEquals(String message, String expected, String actual, boolean removeBlank) {
		if (removeBlank) {
			expected = org.rslai.util.string.Convert.getInstance().removeBlank(expected);
			actual = org.rslai.util.string.Convert.getInstance().removeBlank(actual);
		}
		org.junit.Assert.assertEquals(message, expected, actual);
	}

	public void assertContains (String actual, String containsString) {
		String message = "字符串“" + actual + "”中应包含字符串“" + containsString + "”。";
		this.assertContains(message, actual, containsString, true);
	}

	public void assertContains (String message, String actual, String containsString) {
		this.assertContains(message, actual, containsString, true);
	}

	public void assertContains (String actual, String containsString, boolean removeBlank) {
		String message = "字符串“" + actual + "”中应包含字符串“" + containsString + "”。";
		this.assertContains(message, actual, containsString, removeBlank);
	}

	public void assertContains (String message, String actual, String containsString, boolean removeBlank) {
		if (removeBlank) {
			actual = org.rslai.util.string.Convert.getInstance().removeBlank(actual);
			containsString = org.rslai.util.string.Convert.getInstance().removeBlank(containsString);
		}
		assertThat(message, actual, containsString(containsString));
	}

}
